package com.seeyon.ctp.rest.resources;

import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.brwh.service.SencondDatailService;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.log.CtpLogFactory;
import org.apache.commons.logging.Log;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 获取二级明细扩展接口
 */
@Path("jssdk")
public class SencondDatailResources extends BaseResource {

    private static final Log LOG = CtpLogFactory.getLog(SencondDatailResources.class);

    private SencondDatailService sencondDatailService = (SencondDatailService)AppContext.getBean("sencondDatailService");


    /**
     * 获取需要展示的列表头
     * @return
     */
    @Path("getTitleList")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getTitleList(){
        List<Map<String, Object>> titleList = sencondDatailService.getTitleList();
        return this.ok(titleList);
    }



    /**
     * 获取筛选字段
     * @return
     */
    @Path("getQueryField")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getQueryField(){
        List<Map<String, Object>> titleList = sencondDatailService.getQueryField();
        return this.ok(titleList);
    }


    /**
     * 获取需要回写到表单数据的字段
     * @return
     */
    @Path("getWriteBackField")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getWriteBackField(){
        List<Map<String, Object>> titleList = sencondDatailService.getWriteBackField();
        return this.ok(JSONObject.toJSONString(titleList));
    }


    /**
     * 获取需要展示的列表头
     * @return
     */
    @Path("getDataList")
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getDataList(Map<String,Object> map){
        List<Map<String, Object>> dataList = sencondDatailService.getDataList(map);
        return this.ok(JSONObject.toJSONString(dataList));
    }


    /**
     * 查询二级明细数据
     * @return
     */
    @Path("getSencondDatail")
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getSencondDatail(Map<String,Object> map){
        List<Map<String, Object>> dataList = sencondDatailService.getSencondDatail(map);
        return this.ok(JSONObject.toJSONString(dataList));
    }



    /**
     * 保存二级明细数据
     * @return
     */
    @Path("saveSencondDatail")
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response saveSencondDatail(Map<String,Object> map){
        Map<String, Object> stringObjectMap = sencondDatailService.saveSencondDatail(map);
        return this.ok(stringObjectMap);
    }
}
